package top.yihoxu.answer.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author dth
 * @Date 2024/7/10 17:23
 * @PackageName:top.yihoxu.answer.config
 * @ClassName: RedissonConfig
 * @Description: TODO
 * @Version 1.0
 */
@Configuration
@Data
@ConfigurationProperties(prefix = "spring.redis")
public class RedissonConfig {
    private String host;
    private Integer port;
    private Integer dataBase;
    private String password;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + host + ":" + port)
                .setDatabase(dataBase)
                .setPassword(password);
        return Redisson.create(config);
    }
}
